//
//  HomeDetailHeadView.m
//  GiftNote
//
//  Created by lanou on 15/8/14.
//  Copyright (c) 2015年 GN. All rights reserved.
//

#import "HomeDetailHeadView.h"
#import "HomeHeader.h"
#import "UIImageView+WebCache.h"

@implementation HomeDetailHeadView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(-64, 0, kHomeWidth + 128, 318 * (kHomeWidth + 128) / 700)];
        [self addSubview:_imageView];
        
        
        _view = [[UIView alloc]init];
        _view.backgroundColor = [UIColor blackColor];
        _view.alpha = 0.2;
        [self addSubview:_view];
        
        
        _label = [[UILabel alloc]init];
        _label.textColor = [UIColor whiteColor];
        _label.font = [UIFont systemFontOfSize:20];
        _label.numberOfLines = 0;
        [self addSubview:_label];
        
    }
    return self;
}

- (void)setDetailModel:(HomeDetailModel *)detailModel
{
    _detailModel = detailModel;
    [_imageView sd_setImageWithURL:[NSURL URLWithString:_detailModel.cover_image_url] placeholderImage:nil];
    _label.text = _detailModel.title;
    CGFloat height = [HomeDetailHeadView heightForString:_detailModel.title];
    _label.frame = CGRectMake(0, _imageView.frame.size.height - height + 5, kHomeWidth, height + 10);
    _view.frame = _label.frame;
    
}

+ (CGFloat)heightForString:(NSString *)string
{
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:20] forKey:NSFontAttributeName];
    CGRect bounds = [string boundingRectWithSize:CGSizeMake(kHomeWidth, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return bounds.size.height;
}

@end







